package com.daoyintech.controllers;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.StringUtils;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by xuzhaolin on 15/12/28.
 */
@RestController
@RequestMapping("/weixin")
public class WeixinController{

    @Autowired
    private WxMpService wxMpService;

    @RequestMapping("/verify")
    public Object verify(HttpServletRequest request) {
        String signature = request.getParameter("signature");
        String timestamp = request.getParameter("timestamp");
        String nonce     = request.getParameter("nonce");
        String echostr   = request.getParameter("echostr");
        if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
            return "false";
        }

        if(StringUtils.isNotBlank(echostr)){
            return echostr;
        }

        return "false";
    }


//    @RequestMapping


    @RequestMapping("/hongbao/start")
    public void startHongBao() throws WxErrorException {
        String url = "https://api.weixin.qq.com/shakearound/lottery/setlotteryswitch?access_token={access_token}&lottery_id={}&onoff=1";

    }

}
